﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace WPF_TY_UI
{
    public class LSBPassword : Control
    {

        public override void OnApplyTemplate()
        {


            base.OnApplyTemplate();

            var pwd = GetTemplateChild("PART_password") as PasswordBox;
            if (pwd != null)
            {
                pwd.PasswordChanged += Pwd_PasswordChanged;
            }
        }

        private void Pwd_PasswordChanged(object sender, RoutedEventArgs e)
        {
            this.Password = ((PasswordBox)sender).Password;
        }

        public string Password
        {
            get { return (string)GetValue(PasswordProperty); }
            set { SetValue(PasswordProperty, value); }
        }
        public static readonly DependencyProperty PasswordProperty =
            DependencyProperty.Register("Password", typeof(string), typeof(LSBPassword), new PropertyMetadata(""));


        #region 附加属性 CornerRadius
        public CornerRadius CornerRadius { get { return (CornerRadius)GetValue(CornerRadiusProperty); } set { SetValue(CornerRadiusProperty, value); } }
        public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(LSBPassword), new PropertyMetadata(default(CornerRadius)));
        #endregion

        #region 附加属性 WaterMark
        public string WaterMark { get { return (string)GetValue(WaterMarkProperty); } set { SetValue(WaterMarkProperty, value); } }
        public static readonly DependencyProperty WaterMarkProperty = DependencyProperty.Register("WaterMark", typeof(string), typeof(LSBPassword), new PropertyMetadata(default(string)));
        #endregion

        #region 附加属性 Icon
        public object Icon { get { return (object)GetValue(IconProperty); } set { SetValue(IconProperty, value); } }
        public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(object), typeof(LSBPassword), new PropertyMetadata(default(object)));
        #endregion      

        #region 附加属性 WaterMarkForeground
        public SolidColorBrush WaterMarkForeground { get { return (SolidColorBrush)GetValue(WaterMarkForegroundProperty); } set { SetValue(WaterMarkForegroundProperty, value); } }
        public static readonly DependencyProperty WaterMarkForegroundProperty = DependencyProperty.Register("WaterMarkForeground", typeof(SolidColorBrush), typeof(LSBPassword), new PropertyMetadata(default(SolidColorBrush)));
        #endregion

        public Visibility EyeVisible
        {
            get { return (Visibility)GetValue(EyeVisibleProperty); }
            set { SetValue(EyeVisibleProperty, value); }
        }
        public static readonly DependencyProperty EyeVisibleProperty = DependencyProperty.Register("EyeVisible", typeof(Visibility), typeof(LSBPassword), new PropertyMetadata(Visibility.Collapsed));

        public bool IsShowPassword
        {
            get { return (bool)GetValue(IsShowPasswordProperty); }
            set { SetValue(IsShowPasswordProperty, value); }
        }
        public static readonly DependencyProperty IsShowPasswordProperty = DependencyProperty.Register("IsShowPassword", typeof(bool), typeof(LSBPassword), new PropertyMetadata(false));



    }
}
